package com.itdachang.design.behavioral.memento;

import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author gcq
 * @Create 2022-02-15
 */
public class GameServer {
    Map<Integer, GameRecord> map = new HashMap<>();

    int i = 1;

    void add(GameRecord record) {
        record.setId(i++);
        map.put(record.id, record);
    }

    /**
     * 获取备忘录信息
     * @param id 备忘录 Id
     * @return LeiGame 游戏发起人
     * @throws Exception 对象属性拷贝出错
     */
    LeiGame getRecord(Integer id) throws Exception {
        GameRecord gameRecord = map.get(id);
        LeiGame leiGame = new LeiGame();
        BeanUtils.copyProperties(leiGame, gameRecord);
        return leiGame;
    }
}